<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">

            <h:form id="crumbs">
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexImovel.xhtml')}" value="Imóvel" update="@form" immediate="true"/> >
                    <p:commandLink  value="Cadastrar Imóvel" update="@form" immediate="true"/>
                </div>
            </h:form>
            <p:focus  context="panelCriarImovel"/>
            <p:panel id="panelCriarImovel" header="Cadastrar Imóvel">

                <h:form acceptcharset="utf-8" id="criarImovel" enctype="multipart/form-data"> 
                    <p:messages id="msg"/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Cartório"/></legend>
                        <h:panelGrid  columns="6" style="width:99%;" styleClass="textAlignRight">  

                            <p:row>
                                <h:outputLabel value="*" style="color:red;" styleClass="textAlignRight"/>
                                <h:outputLabel value="Origem: " />
                            </p:row>

                            <p:row>
                                <p:autoComplete id="operacao" value="#{managerImovel.operacao}" 
                                                completeMethod="#{managerOperacao.completeOperacao}"   
                                                var="o" itemLabel="#{o.tipo}" itemValue="#{o}" 
                                                converter="operacaoConverter" forceSelection="true" 
                                                minQueryLength="3" label="Origem do Imóvel"
                                                dropdown="true" required="true" size="16" > 
                                    <p:ajax event="itemSelect" listener="#{managerImovel.handleSelect}" 
                                            process="@this" update=":criarImovel:panelGridTitulo,
                                            :criarImovel:panelGridRegAnterior, :criarImovel:panelGridObjeto"/>  

                                </p:autoComplete>
                                <p:selectOneMenu rendered="false" style="width: 178px"
                                                 value="#{managerImovel.imovel.operacao}"  
                                                 label="Origem do Imóvel" required="true" >  
                                    <f:selectItem itemLabel="Selecione" value="#{null}"/>                   
                                    <f:selectItems value="#{managerOperacao.selectItemOperacao()}"
                                                   var="op" itemLabel="#{op.description}" itemValue="#{op.va}" />                   
                                </p:selectOneMenu> 

                            </p:row>

                            <h:outputLabel value="Livro: " />
                            <p:autoComplete id="livro" value="#{managerImovel.imovel.livro}" 
                                            completeMethod="#{managerLivro.completeLivro}"   
                                            var="li" itemLabel="#{li.titulo}" itemValue="#{li}" 
                                            converter="livroConverter" forceSelection="true" 
                                            minQueryLength="3" label="Livro"
                                            dropdown="true" required="true" size="16" > 

                                <p:ajax event="itemSelect" listener="#{managerImovel.handleSelectLivro}" 
                                        process="@this" update="pag"/>  

                            </p:autoComplete>
                            <h:outputLabel value="Folhas: " />
                            <p:row>
                                <p:inputText id="pag" value="#{managerImovel.folhas}"/>
                                <p:tooltip for="pag" value="Separe as páginas por - (Traço)" 
                                           showEvent="focus" hideEvent="blur" /> 
                            </p:row>

                            <p:row>
                                <h:outputLabel value="*" style="color:red;" styleClass="textAlignRight"/>
                                <h:outputLabel value="Registro: " for="imovel_registro"/> 
                            </p:row>

                            <p:inputMask value="#{managerImovel.imovel.registro}" id="imovel_registro"
                                         required="true" label="Registro"   mask="99999"/>

                            <p:row>
                                <h:outputLabel value="*" style="color:red;" styleClass="textAlignRight"/>
                                <h:outputLabel value="Data:" for="data"/>                       
                            </p:row>


                            <p:calendar value="#{managerImovel.imovel.dataCadastro}" label="Data" 
                                        id="data" mode="popup" showOn="both" 
                                        pattern="dd/MM/yyyy" required="true" size="16"/>

                            <h:outputLabel value="" for="data"/>         

                            <h:outputLabel value="" for="data"/>         

                        </h:panelGrid>
                    </fieldset>

                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Titulo"/></legend>
                        <h:panelGrid columns="2" id="panelGridTitulo" 
                                     styleClass="textAlignRight" columnClasses="textAlignRight">

                            <p:row>
                                <h:outputLabel value="*" style="color:red;" styleClass="textAlignRight"/>
                                <h:outputLabel value="Titulo: " for="titulo"/>                                    
                            </p:row>

                            <p:row>
                                <p:autoComplete id="titulo" value="#{managerImovel.transferencia.titulo}" 
                                                completeMethod="#{managerTitulo.completeTitulo}"  
                                                var="p" itemLabel="#{p.nome}" itemValue="#{p}" 
                                                converter="tituloConverter" forceSelection="true" 
                                                converterMessage="Erro, verifique o titulo" minQueryLength="3" 
                                                dropdown="true" required="true" label="Titulo" > 
                                    <p:ajax event="itemSelect" listener="#{managerImovel.handleSelectTitulo}"/>                                        

                                </p:autoComplete>

                                <h:outputLabel value="Valor do Imóvel: " for="valor" style="float:none;"/>
                                <p:inputText value="#{managerImovel.transferencia.valor}" id="valor"
                                             onchange="jQuery(this).autoNumeric({aSep: '.', aDec: ','} );">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </p:inputText>
                            </p:row>

                            <h:outputLabel value="Forma titulo: " for="formaTitulo"/>
                            <p:inputTextarea value="#{managerImovel.transferencia.formaTitulo}"
                                             id="formaTitulo" cols="100" rows="4" autoResize="true" />

                        </h:panelGrid>

                    </fieldset>

                    <fieldset class="ui-fieldset" >
                        <legend><h:outputLabel value="Registro Anterior"/></legend>

                        <h:panelGrid columns="2" id="panelGridRegAnterior" 
                                     styleClass="textAlignRight" columnClasses="textAlignRight">

                            <h:outputLabel value="* Operação não requer Registro Anterior " 
                                           style="margin-left:20px;"
                                           rendered="#{!managerImovel.operacao.regAnterior}" />

                            <h:outputLabel value="Número do(s) Registro(s) Cadastrado: "
                                           for="imovel_imovelAnterior" rendered="#{managerImovel.operacao.regAnterior}"/>
                            <p:autoComplete value="#{managerImovel.imovel.imovelAnterior}" 
                                            id="imovel_imovelAnterior" completeMethod="#{managerImovel.completeImovel}"
                                            rendered="#{managerImovel.operacao.regAnterior}"
                                            var="p" itemLabel="#{p.registro}" itemValue="#{p}"
                                            multiple="true" converter="imovelConverter"> 
                                <p:ajax event="itemSelect" listener="#{managerImovel.handleSelectImovel}"/> 
                            </p:autoComplete>

                            <h:outputLabel value="Número do(s) Registro(s) não Cadastrado: "
                                           for="imovelAnteriorSemCadastro" rendered="#{managerImovel.operacao.regAnterior}" />
                            <p:inputText id="imovelAnteriorSemCadastro" rendered="#{managerImovel.operacao.regAnterior}"
                                         value="#{managerImovel.imovelAnteriorSemCadastro}" />

                        </h:panelGrid>
                    </fieldset>


                    <fieldset class="ui-fieldset">
                        <legend>Objeto</legend>
                        <h:panelGrid columns="2" style="width: 100%" 
                                     id="panelGridObjeto" styleClass="textAlignRight" 
                                     columnClasses="textAlignRight">

                            <p:row>
                                <h:outputLabel value="*" style="color:red;" styleClass="textAlignRight"/>
                                <h:outputLabel value="Objeto: " for="tipo_endereco"/> 
                            </p:row>

                            <p:row>
                                <p:selectOneMenu id="tipo_endereco"  style="width: 165px" value="#{managerImovel.objeto.tipo}"  
                                                 label="Objeto" required="true" >  
                                    <f:selectItem itemLabel="Selecione" value="#{null}"/>                   
                                    <f:selectItems value="#{managerPessoa.selectItemTipoEndereco()}"/>                   
                                </p:selectOneMenu> 

                            </p:row>
                            <h:outputLabel value="Área do Imóvel" />
                            <p:inputText value="#{managerImovel.objeto.areaOriginal}" style="width: 165px"
                                         onkeypress="jQuery(this).autoNumeric({aSep: '.', aDec: ',', aSign: ' m²', pSign: 's'} );" >
                                <f:convertNumber pattern="#,###,##0.00"/>
                            </p:inputText>



                            <h:outputLabel value="Descrição: " for="descricaoObjeto"/>
                            <p:row>
                                <p:inputTextarea value="#{managerImovel.objeto.descricao}" 
                                                 id="descricaoObjeto" cols="100" rows="4"
                                                 autoResize="true" />
                                <h4 class="subtitle">Descreva de forma detalhada as informações do referido imóvel *. </h4>
                            </p:row>


                        </h:panelGrid>
                        <fieldset class="ui-fieldset">
                            <legend>Endereço do Imóvel</legend>
                            <h:panelGrid columns="4" style="margin-left: 43px ;" id="panelGridEnd" styleClass="textAlignRight" columnClasses="textAlignRight">
                                <h:outputLabel value="Tipo: " for="tipo_logradouro"/>                                                

                                <p:selectOneMenu id="tipo_logradouro"  style="width: 165px" 
                                                 value="#{managerImovel.objeto.tipo_logradouro}"  
                                                 label="Tipo Logradouro" >  
                                    <f:selectItems value="#{managerPessoa.selectItemTipoLogradouro()}"/>                   
                                </p:selectOneMenu> 



                                <h:outputLabel value="Cep: " for="enderecocep"/>
                                <p:row id="linha">
                                    <p:inputMask mask="99.999-999" value="#{managerImovel.objeto.cep}" id="enderecocep"/>
                                    <p:commandButton icon="ui-icon-search" style="margin-left: 5px" actionListener="#{cepWebService.buscarCEP(managerImovel.objeto)}"
                                                     process="panelGridEnd" update="@form" rendered="false"/>
                                </p:row>
                            </h:panelGrid>
                            <h:panelGrid columns="2" id="panelGridEndRua" styleClass="textAlignRight" columnClasses="textAlignRight">
                                <h:outputLabel value="Logradouro: " for="enderecoRua"/>   
                                <p:inputText value="#{managerImovel.objeto.logradouro}" id="enderecoRua" size="100"/>
                                <h:outputLabel value="Nº: " for="enderecoNumero"/>   
                                <p:row>
                                    <p:inputText value="#{managerImovel.objeto.numero}" size="19" id="enderecoNumero" />
                                    <h:outputText value="  " />
                                    <h:outputText value="Bairro: " for="enderecoBairro" />
                                    <p:inputText value="#{managerImovel.objeto.bairro}" id="enderecoBairro"  />
                                    <h:outputText value=" Cidade: " for="cidade"/>
                                    <p:autoComplete id="cidadeEstado" value="#{managerImovel.objeto.cidade}" 
                                                    completeMethod="#{managerEndereco.completeCidade}"   
                                                    var="cidadeEstado" 
                                                    itemLabel="#{cidadeEstado.nom_cidade} - #{cidadeEstado.cod_estado.nom_estado}" 
                                                    itemValue="#{cidadeEstado}" converter="cidadeConverter"
                                                    forceSelection="true" 
                                                    converterMessage="Erro, verifique a cidade" 
                                                    minQueryLength="3" maxResults="10" scrollHeight="200" dropdown="true"> 
                                    </p:autoComplete>
                                </p:row>
                            </h:panelGrid>
                            <h:panelGrid columns="4" style="margin-left: 27px ;" id="panelGridPais" styleClass="textAlignRight" columnClasses="textAlignRight">


                            </h:panelGrid>

                        </fieldset>
                    </fieldset>
                    <br/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Confrontações "/></legend>   
                        <h:panelGrid columns="2" styleClass="textAlignRight" columnClasses="textAlignRight">  
                            <h:outputLabel value="Frente: " for="frente"/>
                            <p:inputTextarea id="frente" value="#{managerImovel.objeto.frente}" 
                                             cols="100" rows="1"/>
                            <h:outputLabel value="Lado Direito: " for="direito"/>
                            <p:inputTextarea id="direito" value="#{managerImovel.objeto.ladoDireito}"
                                             cols="100" rows="1"/>
                            <h:outputLabel value="Lado Esquerdo: " for="esquerdo"/>
                            <p:inputTextarea id="esquerdo" value="#{managerImovel.objeto.ladoEsquerdo}" 
                                             cols="100" rows="1"/>
                            <h:outputLabel value="Fundo: " for="fundo"/>
                            <p:inputTextarea id="fundo" value="#{managerImovel.objeto.fundo}" 
                                             cols="100" rows="1"/>
                        </h:panelGrid>
                    </fieldset>

                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Georeferenciamento"/></legend>

                        <h:panelGrid columns="3" id="gridRef" styleClass="textAlignRight"  > 
                            <p:row>
                                <h:panelGrid columns="7" id="convertCoor" 
                                             styleClass="textAlignRightBold">
                                    <h:outputLabel value="N" />
                                    <p:inputText  value="#{managerImovel.convN}"  size="12"/>
                                    <h:outputLabel value="E" />
                                    <p:inputText  value="#{managerImovel.convE}"  size="12"/>
                                    <h:outputLabel value="Zona" />
                                    <p:row>
                                        <p:inputText  id="zona" value="#{managerImovel.convZona}"  size="5"/>
                                        <p:watermark for="zona" value="M" /> 
                                    </p:row>

                                    <p:commandButton icon="ui-icon-circle-plus" 
                                                     value="Adicionar"
                                                     actionListener="#{managerImovel.converterCoord()}"
                                                     action="#{managerImovel.initMap()}"
                                                     label="Adicionar"
                                                     title="Adicionar Coordenada"
                                                     update="msg, gridRef, @this"
                                                     style="width: 105px;"
                                                     process="convertCoor, @this" />

                                </h:panelGrid>

                                <p:dataTable var="gf" id="coordList" 
                                             value="#{managerImovel.lstGeoRef}" 
                                             style="width: 515px;" editable="true" rowIndexVar="rowGf">  

                                    <p:ajax event="rowEdit" update=":criarImovel:gmapConflict"
                                            listener="#{managerImovel.initMap()}" /> 
                                    <f:facet name="header">  
                                        Coordenadas  
                                    </f:facet>  
                                    <p:column headerText="#" style="width:5%">  
                                        <h:outputText value="#{rowGf + 1}" />  
                                    </p:column>
                                    <p:column headerText="N" style="width:30%">  
                                        <p:cellEditor>  
                                            <f:facet name="output">  
                                                <h:outputText value="#{gf.convN}" />  
                                            </f:facet>  
                                            <f:facet name="input">  
                                                <p:inputText value="#{gf.convN}" style="width:100%"/>  
                                            </f:facet>  
                                        </p:cellEditor>  
                                    </p:column>  

                                    <p:column headerText="E" style="width:30%">  
                                        <p:cellEditor>  
                                            <f:facet name="output">  
                                                <h:outputText value="#{gf.convE}" />  
                                            </f:facet>  
                                            <f:facet name="input">  
                                                <p:inputText value="#{gf.convE}" style="width:100%" label="Year"/>  
                                            </f:facet>  
                                        </p:cellEditor>  
                                    </p:column>  

                                    <p:column headerText="Zona" style="width:20%">  
                                        <p:cellEditor>  
                                            <f:facet name="output">  
                                                <h:outputText value="#{gf.convZona}" />  
                                            </f:facet>  
                                            <f:facet name="input">  
                                                <p:inputText value="#{gf.convZona}" style="width:100%" label="Year"/>  
                                            </f:facet>  
                                        </p:cellEditor>  
                                    </p:column>  

                                    <p:column style="width:15%">  
                                        <p:rowEditor />  
                                        <p:commandButton icon="ui-icon-circle-close" 

                                                         actionListener="#{managerImovel.removeGeoRef(gf)}"
                                                         disabled="#{managerImovel.lstGeoRef.size() > 1 ? false : true}"
                                                         update=":criarImovel:gridRef, @this, coordList" 
                                                         process=":criarImovel:gridRef, @this"
                                                         label="Excluir Coordenadas"
                                                         title="Excluir Coordenadas"
                                                         style="width:15px; height: 15px;"/>
                                    </p:column>  

                                </p:dataTable>
                            </p:row>
                            <p:column>
                                <p:gmap center="#{managerImovel.centerMap}" id="gmapConflict"
                                        rendered="#{managerImovel.lstGeoRef.size() ge 2 ? true: false}"
                                        zoom="#{managerImovel.zoomMap}" type="HYBRID" 
                                        style="width:300px;height:200px" model="#{managerImovel.polygonModel}">

                                </p:gmap>

                            </p:column>

                        </h:panelGrid>

                        <p:dialog id="dialogConvertCoord" header="Conversor de Coordenadas" 
                                  modal="true" widgetVar="convertCoord" resizable="false"  
                                  showEffect="clip" hideEffect="fold" style="top:50%;">

                            <p:ajax event="close" update=":criarImovel:lstadquirente" listener="#{managerPessoa.clear()}"/> 


                        </p:dialog>



                        <p:dialog widgetVar="gmapIntesc" header="Conflito em GeoLocalização" modal="true" >
                            <h:panelGrid columns="2">
                                <h:panelGrid columns="1"  styleClass="textAlignRightBold" style="width:600px; height:400px">
                                    <p:gmap center="#{managerImovel.centerMap}" zoom="23" type="HYBRID" 
                                            style="width:600px;height:400px"   model="#{managerImovel.polygonIntesction}">

                                    </p:gmap>
                                    <p:row>
                                        <h:panelGrid columns="6"  styleClass="textAlignRightBold" style="width: 74%">
                                            <div style="background-color: #FF9900; border-top: 1px solid #FFFFFF; height: 20px; width: 20px;">
                                            </div>
                                            <h:outputLabel value="Imóvel Desejado" />

                                            <div style="background-color: #d93c3c; border-top: 1px solid #FFFFFF; height: 20px; width: 20px;">
                                            </div>
                                            <h:outputLabel value="Imóvel Conflitante" />

                                            <div style="background-color: #00ff00; border-top: 1px solid #FFFFFF; height: 20px; width: 20px;">
                                            </div>
                                            <h:outputLabel value="Área de Conflito" />
                                        </h:panelGrid>
                                    </p:row>
                                </h:panelGrid>

                                <p:row>
                                    <p:panel id="infoObj" header="Imóvel Conflitante "  style="height: 200px; ">
                                        <h:panelGrid columns="2"  styleClass="textAlignRightBold" style=" width: 90%;">

                                            <h:outputLabel value="Registro: " />
                                            <h:outputText value="#{managerImovel.gmapIntersection.imovel.registro}" />
                                            <h:outputLabel value="Tipo: " />
                                            <h:outputText value="#{managerImovel.gmapIntersection.imovel.objeto.tipo}" />
                                            <h:outputLabel value="Endereço: " />
                                            <h:outputText value="#{managerImovel.gmapIntersection.imovel.objeto.tipo_logradouro.nome.toLowerCase()} #{managerImovel.gmapIntersection.imovel.objeto.logradouro}" />
                                            <h:outputLabel value="Registrado em: " />
                                            <h:outputText value="#{managerImovel.gmapIntersection.imovel.dataCadastro}">
                                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                                            </h:outputText>

                                        </h:panelGrid>
                                    </p:panel>
                                    <p:panel id="infoObjConf" header="Confrontações "  
                                             style="height:70px; overflow: auto;">
                                        <h:panelGrid columns="2"  styleClass="textAlignRightBold" style="width: 60px;">
                                            <h:outputLabel value="Área : " />
                                            <h:outputText value="#{managerImovel.gmapIntersection.area}" >
                                            </h:outputText>
                                        </h:panelGrid>
                                    </p:panel>
                                </p:row>
                            </h:panelGrid>

                        </p:dialog>
                    </fieldset>

                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Adquirente"/></legend>

                        <p:commandButton value="Adicionar" icon="ui-icon-circle-plus" 
                                         style="float:right; margin-left: 5px" 
                                         title="Adicionar Adquirente"
                                         oncomplete="buscaAdquirente.show()" immediate="true"/>
                        <br/> 
                        <br/>
                        <h:panelGrid columns="1" id="lstColAdquirente" width="100%" styleClass="textAlignRight" columnClasses="textAlignRight">             
                            <p:dataTable id="lstadquirente" rows="5"  var="adquirente" value="#{managerImovel.transferencia.adquirente}" emptyMessage="Adicione Adquirente">  
                                <f:facet name="header">  
                                    Adquirentes
                                </f:facet>
                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>
                                <p:column id="modelHeader">  
                                    <f:facet name="header">  
                                        <h:outputText value="Nome" />
                                    </f:facet>  
                                    <h:outputText value="#{adquirente.nome}" />  
                                </p:column>  
                                <p:column>  
                                    <f:facet name="header">  
                                        <h:outputText value="Documento" />  
                                    </f:facet>  
                                    <h:outputText value="#{adquirente.cpf}" />  
                                </p:column> 
                                <p:column style="width:50px;">  
                                    <f:facet name="header">  
                                        <h:outputText value="Remover" />  
                                    </f:facet>
                                    <p:commandButton icon="ui-icon-circle-close"
                                                     actionListener="#{managerImovel.removeListAdquirente(adquirente)}" 
                                                     update=":criarImovel:lstColAdquirente" label="Remover Adquirente"
                                                     immediate="true" ajax="true"/>

                                </p:column>
                                <p:rowExpansion >  
                                    <h:outputText value="Nome: " style="font-weight:bold;" />  
                                    <h:outputText id="nome" value="#{adquirente.nome}" />  
                                    <h:outputText value=" - CPF: " style="font-weight:bold;"/>  
                                    <h:outputText id="year" value="#{adquirente.cpf}" />  
                                    <br/>
                                </p:rowExpansion>  
                            </p:dataTable>  
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Transmitente"/></legend>

                        <p:commandButton value="Adicionar"
                                         title="Adicionar Transmitente"
                                         icon="ui-icon-circle-plus" style="float:right; margin-left: 5px" 
                                         update="msg, :formdialog:colTransmitente, :formdialog:dataTable"
                                         oncomplete="buscaTransmitente.show()" immediate="true"/>
                        <br/> 
                        <br/>
                        <h:panelGrid columns="1" id="lstColTransmitente" width="100%" styleClass="textAlignRight" columnClasses="textAlignRight">             
                            <p:dataTable id="lsttransmitente" rows="5"  var="transmitente" value="#{managerImovel.transferencia.transmitente}" emptyMessage="Adicione Adquirente">  
                                <f:facet name="header">  
                                    Transmitentes
                                </f:facet>
                                <p:column style="width:16px">  
                                    <p:rowToggler />  
                                </p:column>
                                <p:column id="modelHeader">  
                                    <f:facet name="header">  
                                        <h:outputText value="Nome" />
                                    </f:facet>  
                                    <h:outputText value="#{transmitente.nome}" />  
                                </p:column>  
                                <p:column>  
                                    <f:facet name="header">  
                                        <h:outputText value="Documento" />  
                                    </f:facet>  
                                    <h:outputText value="#{transmitente.cpf}" />  
                                </p:column> 
                                <p:column style="width:50px;">  
                                    <f:facet name="header">  
                                        <h:outputText value="Remover" />  
                                    </f:facet>
                                    <p:commandButton icon="ui-icon-circle-close" actionListener="#{managerImovel.removeListTransmitente(transmitente)}" update="@form" immediate="true" ajax="true"/>

                                </p:column>
                                <p:rowExpansion >  
                                    <h:outputText value="Nome: " style="font-weight:bold;" />  
                                    <h:outputText id="nomeTable" value="#{transmitente.nome}" />  
                                    <h:outputText value=" - CPF: " style="font-weight:bold;"/>  
                                    <h:outputText id="cpfTable" value="#{transmitente.cpf}" />  
                                    <h:outputText value=" - Endereco: " style="font-weight:bold;"/>  
                                    <h:outputText id="enderecoTable" value="#{transmitente.endereco}" />  
                                    <br/>
                                </p:rowExpansion>  
                            </p:dataTable>  
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <fieldset class="ui-fieldset" id="fieldAnexo" >
                        <legend>Anexos</legend>


                        <p:fileUpload fileUploadListener="#{managerArquivo.handleFileUpload}"  
                                      mode="advanced"  
                                      update="x"  
                                      multiple="true"
                                      uploadLabel="Anexar"
                                      label="Carregar"
                                      cancelLabel="Cancelar"
                                      allowTypes="/(\.|\/)(gif|jpe?g|png|tif)$/"
                                      invalidFileMessage="Arquivo não suportado, verifique o tipo do arquivo."
                                      invalidSizeMessage="Tamanho do arquivo é inválido."
                                      sizeLimit="3145728"
                                      />  

                        <p:dataTable var="item" id="x"  value="#{managerArquivo.anexoList}" 
                                     rowKey="#{item.id}"
                                     paginatorPosition="bottom"

                                     emptyMessage="Nenhum anexo encontrado"
                                     >  
                            <p:column headerText="Anexos">
                                <p:lightBox  styleClass="imagebox"> 
                                    <h:outputLink value="imageUploadServlet/?anexo=#{item.id}" title="#{item.nome}">  
                                        <h:outputLabel value="#{item.nome}" />
                                    </h:outputLink>  
                                </p:lightBox>                        
                            </p:column>
                            <p:column headerText="Tamanho">

                            </p:column>
                        </p:dataTable>

                    </fieldset>

                    <div class="buttonAction">

                        <p:commandButton id="upa" icon="ui-icon-disk" value="Salvar" 
                                         actionListener="#{managerImovel.criar(managerArquivo.anexoList)}" 
                                         update="@form" oncomplete="parent.window.scrollTo(1,1);" process="@form"/>

                        <p:commandButton id="limpar" icon="ui-icon-close" value="Limpar" 
                                         actionListener="#{managerImovel.init()}" oncomplete="parent.window.scrollTo(1,1);" update="@form" />  

                        <p:ajaxStatus style="width:16px;height:16px;" id="ajaxStatusPanel">  
                            <f:facet name="start">  
                                <h:graphicImage value="/media/img/loading.gif" />  
                            </f:facet>  

                            <f:facet name="complete">  
                                <h:outputText value="" />  
                            </f:facet>  
                        </p:ajaxStatus>

                    </div>

                </h:form>

                <h:form id="formdialog"  acceptcharset="utf-8">
                    <p:messages   id="msgDialog" />
                    <p:dialog id="dialogAdquirente" header="Adicione Adquirente" 
                              modal="true" widgetVar="buscaAdquirente" resizable="false"  
                              showEffect="clip" hideEffect="fold" style="top:50%;">

                        <p:ajax event="close" update=":criarImovel:lstadquirente" listener="#{managerPessoa.clear()}"/> 

                        <h:panelGrid columns="1" id="panelDialogAdquirente" >                            

                            <p:selectOneRadio id="controleAdquirenteSelectOne" value="#{managerPessoa.controleAdquirente}"
                                              label="Selecione um item">
                                <f:selectItem itemLabel="Pessoa Fisica"  itemValue="#{true}"/>
                                <f:selectItem itemLabel="Pessoa Juridica"  itemValue="#{false}"/>
                                <p:ajax  update="filtroPessoaAdquirenteCPF, controleAdquirenteSelectOne, colAdquirente" event="change" />
                            </p:selectOneRadio>

                            <h:panelGrid columns="2" id="colAdquirente" cellpadding="10px" styleClass="textAlignRight" columnClasses="textAlignRight">             
                                <h:outputLabel value="Nome:  " for="filtroPessoaAdquirenteNome"/> 
                                <p:inputText value="#{managerPessoa.pessoa.nome}" 
                                             id="filtroPessoaAdquirenteNome" maxlength="60" size="70" />

                                <h:outputLabel value="Documento: " for="filtroPessoaAdquirenteCPF"/> 
                                <p:row>
                                    <p:inputText value="#{managerPessoa.controleAdquirente ? managerPessoa.pessoa.cpf : managerPessoa.pessoa.cnpj}" 
                                                 id="filtroPessoaAdquirenteCPF" maxlength="60" />                        
                                </p:row>
                            </h:panelGrid>

                            <p:row>

                                <div class="buttonAction" >
                                    <p:commandButton value="Buscar" 
                                                     process="panelDialogAdquirente" icon="ui-icon-search"
                                                     actionListener="#{managerPessoa.buscar()}" 
                                                     update="dataTable, msgDialog" />
                                    <p:commandButton value="Fechar" 
                                                     process="colAdquirente" icon="ui-icon-close"
                                                     onclick="buscaAdquirente.hide()" 
                                                     update="dataTable, msgDialog" />
                                </div>
                            </p:row>
                            <p:dataTable var="item" id="dataTable" value="#{managerPessoa.listpessoa}" 
                                         rowKey="#{item.id}"
                                         selection="#{managerPessoa.pessoaaux}"
                                         selectionMode="single"
                                         paginator="true" rows="10"
                                         paginatorPosition="bottom"
                                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                         emptyMessage="Nenhum registro encontrado"
                                         >  
                                <p:ajax event="rowSelect" listener="#{managerImovel.selecionaAdquirente(managerPessoa.selecionaPessoa())}" update=":criarImovel:lstadquirente"/>
                                <p:column  id="pessoaNome" headerText="Nome">
                                    #{item.nome}
                                </p:column>
                                <p:column  id="pessoaCPF" headerText="Documento">
                                    #{managerPessoa.controleAdquirente ? item.cpf : item.cnpj}
                                </p:column>
                            </p:dataTable>
                        </h:panelGrid>
                    </p:dialog>
                    <p:dialog id="dialogTransmitente" header="Adicione Transmitente" modal="true" 
                              widgetVar="buscaTransmitente" resizable="false"  
                              showEffect="clip" hideEffect="fold" style="top:50%;">

                        <p:ajax event="close" update=":criarImovel:lsttransmitente" listener="#{managerPessoa.clear()}"/> 

                        <h:panelGrid columns="1" id="panelDialogTransmitente" >
                            <p:selectOneRadio id="controleTransmitenteSelectOne" value="#{managerPessoa.controleTransmitente}"
                                              label="Selecione um item">
                                <f:selectItem itemLabel="Pessoa Fisica"  itemValue="#{true}"/>
                                <f:selectItem itemLabel="Pessoa Juridica"  itemValue="#{false}"/>
                                <p:ajax update="filtroPessoaTransmitenteCPF, controleTransmitenteSelectOne, colTransmitente" event="change"/>
                            </p:selectOneRadio>
                            <h:panelGrid columns="2" id="colTransmitente" cellpadding="10px" styleClass="textAlignRight" columnClasses="textAlignRight">             
                                <h:outputLabel value="Nome:  " for="filtroPessoaTransmitenteNome"/> 
                                <p:inputText value="#{managerPessoa.pessoa.nome}" 
                                             id="filtroPessoaTransmitenteNome" maxlength="60" size="70"/>

                                <h:outputLabel value="Documento: " for="filtroPessoaTransmitenteCPF"/> 
                                <p:row>
                                    <p:inputText value="#{managerPessoa.controleTransmitente ? managerPessoa.pessoa.cpf : managerPessoa.pessoa.cnpj}" 
                                                 id="filtroPessoaTransmitenteCPF" maxlength="60"/>                        
                                </p:row>
                            </h:panelGrid>
                            <p:row>

                                <div class="buttonAction" >
                                    <p:commandButton value="Buscar"
                                                     icon="ui-icon-search"
                                                     style="margin-left: 5px" process="panelDialogTransmitente" 
                                                     actionListener="#{managerPessoa.buscarTransmitente()}"
                                                     update="dataTableTransmitente, msgDialog" />

                                    <p:commandButton value="Fechar" 
                                                     process="colTransmitente" icon="ui-icon-close"
                                                     onclick="buscaTransmitente.hide()" 
                                                     update="dataTableTransmitente, msgDialog" />
                                </div>
                            </p:row>
                            <p:dataTable var="item" id="dataTableTransmitente" value="#{managerPessoa.listpessoaTrans}" 
                                         rowKey="#{item.id}"
                                         selection="#{managerPessoa.pessoaauxTrans}"
                                         selectionMode="single"
                                         paginator="true" rows="10"
                                         paginatorPosition="bottom"
                                         paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                         emptyMessage="Nenhum registro encontrado"
                                         >  
                                <p:ajax event="rowSelect" listener="#{managerImovel.selecionaTransmitente(managerPessoa.selecionaPessoaTrans())}" update=":criarImovel:lsttransmitente"/>
                                <p:column  id="pessoaNome" headerText="Nome">
                                    #{item.nome}
                                </p:column>
                                <p:column  id="pessoaCPF" headerText="Documento">

                                    #{managerPessoa.controleTransmitente ? item.cpf : item.cnpj}
                                </p:column>
                            </p:dataTable>
                        </h:panelGrid>
                    </p:dialog>
                </h:form>
            </p:panel>
            <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
        </ui:define>
    </ui:composition>
</html>

